//引入一级路由组件
import home from '@/views/Home';
import Search from '@/views/Search';
import Login from '@/views/Login';
import Register from '@/views/Register';
import Detail from '@/views/Detail';
import AddCartSuccess from '@/views/AddCartSuccess'
import ShopCart from '@/views/ShopCart'
import Trade from '@/views/Trade';
import Pay from '@/views/Pay'
import PaySuccess from '@/views/PaySuccess';
import Center from '@/views/Center'

//个人中心的二级路由组件
import MyOrder from '@/views/Center/modules/myOrder.vue'
import TeamOrder from '@/views/Center/modules/teamOrder.vue'

export default [
    // 首页
    {
        path: '/home',
        name: 'erha',
        component: home,
        //路由元 给当前路由添加一些额外数据
        //它的右侧是一个对象[可以有多个键值对]
        meta: { show: true },
    },
    // 搜索
    {
        //命名路由,给路由起一个名字
        name: 'search',
        //在注册路由的时候,如果这里占位，切记务必要传递params
        path: '/search/:keyword?',
        component: Search,
        meta: { isShow: true },
    },
    // 登录
    {
        path: '/login',
        component: Login,
        meta: { show: false },
    },
    // 注册
    {
        path: '/register',
        component: Register,
        meta: { show: false },
    },
    //重定向到首页
    {
        path: '/',
        redirect: '/home'
    },
    // 商品详情
    {
        path: '/detail/:skuId?',
        component: Detail,
        //路由元信息,控制当前路由是否需要Footer组件
        meta: { show: true },
    },
    // 成功加入购物车
    {
        path: '/addcartsuccess',
        name: 'addcartsuccess',
        component: AddCartSuccess,
        //路由元信息,控制当前路由是否需要Footer组件
        meta: { show: true },
    },
    // 购物车
    {
        path: '/shopcart',
        component: ShopCart,
        meta: { show: true }
    },
    // 交易（创建订单)
    {
        path: '/trade',
        component: Trade,
        meta: { show: true },
        // 独享守卫
        beforeEnter: (from, next) => {
            if (from.path == '/shopcart') {
                next()
            } else {
                next(false) // 中断当前导航，从哪来回哪去
            }
        }
    },
    // 支付
    {
        path: '/pay',
        component: Pay,
        meta: { show: true },
        // 独享守卫
        beforeEnter: (from, next) => {
            if (from.path == '/trade') {
                next()
            } else {
                next(false) // 中断当前导航，从哪来回哪去
            }
        }
    },
    // 支付成功
    {
        path: '/paysuccess',
        component: PaySuccess,
        meta: { show: true }
    }
    ,
    // 个人中心
    {
        path: '/center',
        component: Center,
        meta: { show: true },
        //二级路由配置的地方
        children: [
            //我的订单
            {
                path: 'myorder',
                component: MyOrder
            }
            ,
            {
                path: 'teamorder',
                component: TeamOrder
            }
            ,
            {
                path: '/center',
                redirect: '/center/myorder'
            }
        ]
    },
]